<template>
  <v-app id="app">
    <!-- 导航栏 -->
    <TopNavBar />
    <!-- 侧边导航栏 -->
    <SideNavBar />
    <!-- 内容 -->
    <v-content>
      <router-view :key="$route.fullPath" />
    </v-content>
    <!-- 页脚 -->
    <Footer />
    <!-- 返回顶部 -->
    <BackTop />
    <!-- 搜索模态框 -->
    <searchModel />
    <!--    <FeedBack />-->
  </v-app>
</template>

<script>
import TopNavBar from './components/layout/TopNavBar'
import SideNavBar from './components/layout/SideNavBar'
import Footer from './components/layout/Footer'
import BackTop from './components/BackTop'
import searchModel from './components/model/SearchModel'
import {getWebBasicInfo} from './api'

let BLOG_APPLICATION_KEY = 'BLOG_APPLICATION'

export default {
  components: {
    TopNavBar,
    SideNavBar,
    Footer,
    BackTop,
    searchModel,
  },
  computed: {
    blogInfo() {
      return this.$store.state.blogInfo
    },
    isMobile() {
      return navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
      )
    }
  },
  created() {
    this.getBlogInfo()
    this.consoleLog()
  },
  methods: {
    getBlogInfo() {

      let blogApplicationJson = sessionStorage.getItem(BLOG_APPLICATION_KEY)
      if (blogApplicationJson){
        try {
          let obj = JSON.parse(blogApplicationJson)

          //判断当前时间戳是否距离当前大于俩小时
          let now = new Date()
          if ((Math.abs(now.getTime() - obj.cacheTimestamp) / (1000 * 60)) <= 120){
            this.$store.commit('updateBlogInfo', obj.info)
            return
          }
        }catch (e) {
          console.log('去请求娄')
        }
      }
      getWebBasicInfo().then(res => {
        if (res.data.code !== 2000){
          this.$toast({type: 'warnning', message: '网管正在紧急修复中，先看个视频放松一下吧'})
          setTimeout(()=>{
            window.location.href = 'https://www.bilibili.com/v/dance/?spm_id_from=333.1073.0.0'
          },500)
          return
        }
        let data = res.data.data
        data.countNum = JSON.parse(data.countJson)
        this.$store.commit('updateBlogInfo', data)

        let BLOG_APPLICATION = {
          cacheTimestamp: new Date().getTime(),
          info: data
        }
        //首次访问后将内容写入到浏览器 有效期为两小时
        sessionStorage.setItem(BLOG_APPLICATION_KEY,JSON.stringify(BLOG_APPLICATION))
      })
    },
    consoleLog() {
      let styleTitle1 = `
        font-size: 20px;
        font-weight: 600;
        color: rgb(244,167,89);
        `
      let styleTitle2 = `
        font-style: oblique;
        font-size:14px;
        color: rgb(244,167,89);
        font-weight: 400;
       `
      let styleContent = `
        color: rgb(30,152,255);
        `
      let title1 = '小徐博客系统 '
      
      // => 读取配置型(在配置文件里配置这些会变动的网址)
      let offiUrl = 'https://xqijun.top'
      let content = `
版 本 号：3.0
版权声明：
1. 本博客系统部分图片来源于网络，如有侵权联系删除！
2. 本站文章及资源，任何个人和机构在遵守下列条件的前提下授权永久使用：
  1)不进行任何形式的破解和裁剪，完整引用
  2)保留此版权信息在控制台输出
我们保留对此版权信息的最终解释权.
🏠官网:  ${offiUrl}
✨邮箱:  xuqijun@xqijun.top
        `
      console.log(`%c${title1}  %c${content}`, styleTitle1, styleContent)
    }
  }
}
</script>
